var util = require('../../../libs/util.js');
var app = getApp();
var sliderWidth = 120; // 需要设置slider的宽度，用于计算中间位置
Page({
  data: {
    hasData: true,
    stock_data:[]
  },
  onPullDownRefresh: function () {
    //wx.stopPullDownRefresh()
  },
  onLoad: function (e) {
    var that = this;
    wx.setNavigationBarTitle({ "title": app.appName +"--库存详情" });
    wx.showToast({
      title: "数据加载中...",
      icon: 'loading',
      duration: 3000
    });
    that.setData({
      id:e.id,
      name:e.name,
      count:e.count
    })
    this.loadData();
  },
  onShareAppMessage: function () {
    return {
      title: app.appName,
      path: '/pages/index/index'
    }
  },
  loadData: function () {
    var that = this;
    wx.request({
      url: app.server + '/wechat/wxapplet/getStockDetail',
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'Cookie':app.globalData.cookie
      },
      data: {
        id: that.data.id
      },
      success: function (res) {
        wx.hideToast();
        console.log(res.data)
        var stock_data = res.data.data;
        if (res.data.success && stock_data.length > 0) {
          that.setData({
            hasData: true,
            stock_data: stock_data
          });

        } else {
          that.setData({
            hasData: false
          })
        };
      },
      fail: function (error) {
        wx.hideToast();
        console.log(error);
        that.setData({
          hasData: false
        })
      }
    })
  },
  backToStock: function (e) {
    wx.navigateBack({
      delta: 1
    })
  },
  warehouseMonitor: function () {
    wx.redirectTo({
      url: '/pages/warehouse/warehouse'
    })
  },
  warehouseStock: function () {
    wx.redirectTo({
      url: '/pages/warehouse/stock'
    })
  },
  goodsManage: function () {
    wx.redirectTo({
      url: '/pages/warehouse/goods'
    })
  }
})
